package q198_rob;

public class Solution_2 {
    public int rob(int[] nums) {
        if (nums.length <= 2) {
            return nums.length == 1 ? nums[0] : Math.max(nums[1],nums[0]);
        }

        int p = nums[0];
        int q = Math.max(nums[1], nums[0]);
        int r = Math.max(nums[1], nums[0]);
        for (int i = 2; i < nums.length; i++) {
            // robs[i] = Math.max(robs[i - 2] + nums[i], robs[i - 1]);
            r = Math.max(p + nums[i], q);
            p = q;
            q = r;
        }

        return r;
    }

}
